﻿namespace USElections.NewsFeeds.Model
{
    using AgFx;

    /// <summary>
    /// Data class.
    /// </summary>
    public class Data
    {
        #region Fields
        private static readonly Data instance = new Data();
        private RssFeeds rssFeeds = new RssFeeds();
        #endregion

        #region Constructor
        /// <summary>
        /// Initializes static members of the Data class.
        /// </summary>
        static Data()
        {
        }

        /// <summary>
        /// Prevents a default instance of the Data class from being created.
        /// </summary>
        private Data()
        {
        }
        #endregion

        #region Properties
        /// <summary>
        /// Gets the Data instance.
        /// </summary>
        public static Data Instance
        {
            get
            {
                return instance;
            }
        }

        /// <summary>
        /// Gets the Rss feeds.
        /// </summary>
        public RssFeeds RssFeeds
        {
            get
            {
                if (this.rssFeeds == null || this.rssFeeds.Count == 0)
                {
                    this.PopulateRssFeeds();
                }

                return this.rssFeeds;
            }
        }
        #endregion

        #region Private methods
        private void PopulateRssFeeds()
        {
            RssFeedModel nytimesRssFeed = DataManager.Current.Load<RssFeedModel>(new RssFeedLoadContext("NY Times", "http://www.nytimes.com/services/xml/rss/nyt/Politics.xml"), (lc) => { }, (lc) => { });
            RssFeedModel gallupRssFeed = DataManager.Current.Load<RssFeedModel>(new RssFeedLoadContext("Gallup", "http://www.gallup.com/tag/Election+2012.rss"), (lc) => { }, (lc) => { });
            RssFeedModel cnnRssFeed = DataManager.Current.Load<RssFeedModel>(new RssFeedLoadContext("CNN", "http://rss.cnn.com/rss/cnn_allpolitics.rss"), (lc) => { }, (lc) => { });

            RssFeedModel fivethreeeightRssFeed = DataManager.Current.Load<RssFeedModel>(new RssFeedLoadContext("538 (NYT)", "http://fivethirtyeight.blogs.nytimes.com/feed/"), (lc) => { }, (lc) => { });
            RssFeedModel caucusRssFeed = DataManager.Current.Load<RssFeedModel>(new RssFeedLoadContext("Caucus (NYT)", "http://thecaucus.blogs.nytimes.com/feed/"), (lc) => { }, (lc) => { });

            RssFeedModel washPostRssFeed = DataManager.Current.Load<RssFeedModel>(new RssFeedLoadContext("Washington Post", "http://feeds.washingtonpost.com/rss/rss_election-2012"), (lc) => { }, (lc) => { });

            /* Huffington Post RSS Feed doesn't comply to standards */

            this.rssFeeds.Add(nytimesRssFeed);
            this.rssFeeds.Add(gallupRssFeed);
            this.rssFeeds.Add(cnnRssFeed);

            this.rssFeeds.Add(fivethreeeightRssFeed);
            this.rssFeeds.Add(caucusRssFeed);

            this.rssFeeds.Add(washPostRssFeed);
        }
        #endregion
    }
}